{% extends "base.html" %}

{% block header%}
<title>分支列表</title>
{% endblock %}

{% block content %}
{% with model_name='Branch' url_prefix='/pack/task/open_branch_detail' active_url='/pack/branch/branch' freeze_url='/pack/task/freeze_branch_detail' %}
<script type="text/javascript">
    var request_url = '/pack/branch/branch',
        ColumnDefs = [
            {
                "aTargets": [1],
                "sWidth":"15%",
                "mData": function (source) {
                    if(source[1] !== "无"){
                        return "<a href='/pack/log/log_detail?model=branch&id=" + source[5] +
                                "' class='openDialog'>" + source[1] + "</a> &nbsp;&nbsp;";
                    } else {
                        return source[1]
                    }
                }
            },
            {
                "aTargets": [2],
                "sWidth":"15%",
                "mData": function (source) {
                    if(source[2] !== "无"){
                        return "<a href='/pack/log/log_detail?model=prev_branch&id=" + source[5] +
                                "' class='openDialog'>" + source[2] + "</a> &nbsp;&nbsp;";
                    } else {
                        return source[2]
                    }

                }
            },
            {
                "aTargets": [4],
                "sWidth":"12%",
                "mData": function (source) {
                    var state_s = "冻结";
                    if(source[4] === 1){
                        state_s = "激活";
                    }
                    return state_s
                }
            },
            {
                "aTargets": [5],
                "sWidth":"25%",
                "mData": function (source) {
                    var base_str = "";
                    if(source[4] === 0){
                        base_str = "<a href='javascript:void(0);' onclick='active{{model_name}}(" +
                            source[5]+ ")'>激活</a>";
                    } else {
                        base_str = "<a href='/pack/task/freeze_branch_detail?id=" + source[5] +
                         "' class='openDialog'>冻结</a>"
                    }
                    return "<a href='/pack/task/pack_pc_detail?id=" + source[5] +
                        "' class='openDialog'>打包PC端</a> &nbsp;&nbsp;" +
                        "<a href='/pack/task/pack_mobile_detail?id=" + source[5] +
                        "' class='openDialog'>打包移动端</a> &nbsp;&nbsp;" +
                        "<a href='/pack/task/release_version_detail?b_id=" + source[5] +
                        "' class='openDialog'>发布版本</a> &nbsp;&nbsp;" + base_str;
                        {#"<a href='/pack/task/freeze_branch_detail?id=" + source[5] +#}
                        {#"&state_s=" + state_s + "&state=" + state +#}
                        {#"' class='openDialog'>" + state_s + "</a> &nbsp;&nbsp;"   #}
                }
            },
        ];

	function add{{model_name}}(ele) {
		art.dialog.open("{{url_prefix}}")
	}

    function active{{model_name}}(id){
		if (confirmRandom('确定激活吗?')){
            $.ajax({
               url:'{{active_url}}?state=1&id='+id,
               type:'PUT',
               success:function (result) {
                    if(result){
                       window.location.reload();
                   }else{
                       alert("激活失败！")
                   }
               }
           })
		}
	}

	{#function freeze{{model_name}}(id){#}
	{#	if (confirmRandom('确定冻结吗?')){#}
    {#        $.ajax({#}
    {#           url:'{{freeze_url}}?state=0&id='+id,#}
    {#           type:'POST',#}
    {#           data: {#}
    {##}
    {#           },#}
    {#           success:function (result) {#}
    {#                if(result){#}
    {#                   window.location.reload();#}
    {#               }else{#}
    {#                   alert("冻结失败！")#}
    {#               }#}
    {#           }#}
    {#       })#}
	{#	}#}
	{# }#}

	{#function edit{{model_name}}(ele){#}
	{#    console.log(ele);#}
		{#var s_id = #}
	{#    art.dialog.open("{{url_prefix}}?id=" + selectId)#}
	{# }#}
	{#function remove{{model_name}}(ele){#}
	{#	if (confirmRandom('确定删除吗?')){#}
	{#		window.location.href = "{{url_prefix}}remove?"+$('#{{model_name}}_area :checkbox').serialize()#}
	{#	}#}
	{# }#}
	{#function recover{{model_name}}(ele){#}
	{#	if (confirm('确定恢复吗?')) {#}
	{#		window.location.href = "{{url_prefix}}remove?recover=true&"+$('#{{model_name}}_area :checkbox').serialize()#}
	{#	}#}
	{# }#}

{#$(function(){#}
    {# $('#{{model_name}}_area tr').contextMenu('contextMenu',#}
    {# {#}
    {#      bindings:#}
    {#      {#}
    {#        'c_edit': function(t) {#}
    {#           edit{{model_name}}(t)#}
    {#        },#}
    {#        'c_remove': function(t) {#}
    {#           remove{{model_name}}(t)#}
    {#        },#}
    {#        'c_recover':function(t){#}
    {#        recover{{model_name}}(t)#}
    {#        }#}
    {#      }#}
    {##}
    {# });#}
{#    select_checkbox();#}
{#    $('#a_submit').click(function(){#}
{#        var aObjData = $('#search_form').find('[name]').serializeArray();#}
{#        var params = "";#}
{#        for (var item in aObjData){#}
{#            params += aObjData[item].name + "=" + aObjData[item].value + "&";#}
{#        }#}
{#        $('#{{model_name}}_table').dataTable().fnDestroy();#}
{#        opt.sAjaxSource = (request_url + "?" + params).replace(/([?&]$)/g,"");#}
{#        $('#{{model_name}}_table').DataTable(opt);#}
        {#$.ajax({#} //方案一
        {#    type: 'GET',#}
        {#    url: request_url + "?" + params,#}
        {#    datatype: "json",#}
        {#    success: function(data) {#}
        {#      console.log("成功");#}
        {#      var settings = $('.datatable').DataTable().fnSettings();#}
        {#      console.log(data);#}
        {#        settings.aaData = data;#}
        {#        console.log(settings);#}
        {#        $('.datatable').DataTable().fnDraw();#}
        {#    },#}
        {#    error: function(data) {#}
        {#      console.log("失败");#}
        {#    }#}
        {# });#}
        {#方案二#}
        {#var settings = $('.datatable').DataTable().fnSettings();#}
        {#settings.sAjaxSource = request_url + "?" + params;#}
        {#$('.datatable').DataTable()._fnAjaxUpdate(settings);#}
{#    });#}
{#    click_submit();#}
{#    $('#search_form').find('[name]').click(update_local_strorage);#}
{# })#}
</script>

{% include 'query/plugins/search_form.html' %}

{#<div  id="contextMenu" class="contextMenu">  #}
{#	<ul>  #}
{#		<li id="c_edit" class="btn no-border btn-white" ><i class="icon-edit"></i>编辑</li>  #}
{#<!-- 		<li id="c_remove" class="btn no-border btn-white" ><i class="icon-trash"></i>删除</li>     -->#}
{#		<li id="c_recover" class="btn no-border btn-white" ><i class="icon-share-alt "></i>恢复</li>    #}
{#	</ul>  #}
{#</div> #}

<div >
	<ul id="nav-list" class="nav nav-tabs" >
			  <li class="active"  >
			  	<a>分支列表</a>
			  </li>
	</ul>
	<!-- 按钮工具条 -->
	<div id='datatable_toolbar'>
		<div class="btn-toolbar pull-right">
			<div class="btn-group ">
				<a class="btn btn-sm btn-success " onclick="add{{model_name}}(this)">
					<i class="icon-plus-sign"></i>添加
				</a>
			</div>
{#			<div class="btn-group">#}
{#				<a class="btn btn-sm btn-primary " onclick="edit{{model_name}}(this)">#}
{#					<i class="icon-edit"></i>编辑#}
{#				</a>#}
{#				<a data-toggle="dropdown" class="btn btn-sm  btn-primary dropdown-toggle">#}
{#					<span class="icon-caret-down icon-only"></span>#}
{#				</a>#}
{#				<ul class="dropdown-menu">#}
{#					<li>#}
{#						<a  class="" onclick="remove{{model_name}}(this)">#}
{#							<i class="icon-trash "></i> 删除#}
{#						</a>#}
{#						<a  class="" onclick="recover{{model_name}}(this)">#}
{#							<i class="icon-share-alt "></i> 恢复#}
{#						</a>#}
{#					</li>#}
{#				</ul>#}
{#			</div>#}
		</div>
	</div>
	<table  id="{{model_name}}_table" class="table table-bordered datatable" data-toolbar='datatable_toolbar' data-group-by-index='[5]'>
		<thead>
		<tr>
            <th>项目</th>
            <th>分支名称</th>
			<th>前置分支名称</th>
			<th>创建时间</th>
			<th>状态</th>
			<th>操作</th>
		</tr>
		</thead>
		<tbody id="{{model_name}}_area"></tbody>
	</table>
</div>
{% endwith %}
{% endblock %}
